package com.sky.controller.user;


import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController("userDishController")
@RequestMapping("/user/dish")
@Api(tags = "菜品模块")
public class DishController {

    @Autowired
    private DishService dishService;

    @ApiOperation("分类id查询菜品")
    @GetMapping("list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result findByCategoryId (Long categoryId ){
        log.info("分类id查询菜品{}", categoryId);
        Dish dish = Dish.builder()
                .categoryId(categoryId)
                .status(StatusConstant.ENABLE)
                .build();

        return Result.success(dishService.findByCategoryIdWithFlavour(dish));
    }
}
